package cn.usersmsg.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * 日期处理类
 * @author Administrator
 *
 */
public class DateUtil {
	/**
	 * 字符串转换 java日期
	 * @param strDate
	 * @return
	 */
	public static Date stringToJavaDate(String strDate){
		Date date = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			date = sdf.parse(strDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;		
	}
	/**
	 * 字符串转换 sql日期
	 * @param strDate
	 * @return
	 */
	public static java.sql.Date stringToSqlDate(String strDate){
		java.sql.Date date = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			date = new java.sql.Date(sdf.parse(strDate).getTime());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;		
	}
	/**
	 * java日期转换字符串
	 * @param date
	 * @return
	 */
	public static String javaDateToString(Date date){
		String strDate = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		strDate = sdf.format(date);
		return strDate;		
	}
	/**
	 * sql日期转换字符串
	 * @param date
	 * @return
	 */
	public static String sqlDateToString(java.sql.Date date){
		String strDate = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		strDate = sdf.format(date);
		return strDate;		
	}
}
